<template>
  <div class="choose-analyze-lat">
    <div class="model-list">
      <div
        v-for="(model, index) in modelList"
        :key="index"
        class="model-item"
        :class="{ active: selectedModel === model.key }"
        @click="selectModel(model.key)"
      >
        <div class="radio-btn">
          <div class="radio-inner" v-if="selectedModelKey === model.key"></div>
        </div>
        <div class="model-info">
          <div class="model-name">{{ model.name }}</div>
          <div class="model-desc">{{ model.description }}</div>
        </div>
      </div>
    </div>
    <div class="confirm-btn" @click="handleConfirm">确定</div>
  </div>
</template>

<script>
import { getModelList, getModelWithKey } from "./modelMap";
export default {
  name: "ChooseAnalyzeLat",
  props: {
    defaultSelectedModelKey: {
      type: String,
    },
  },
  data() {
    return {
      selectedModelKey: this.defaultSelectedModelKey,
      modelList: getModelList(),
    };
  },
  methods: {
    selectModel(key) {
      this.selectedModelKey = key;
    },
    handleConfirm() {
      const selectedModelObj = getModelWithKey(this.selectedModelKey);
      this.$emit("confirm", selectedModelObj);
    },
  },
};
</script>

<style scoped>
.choose-analyze-lat {
  padding: 20px;
  background: #fff;
  height: 100vh;
}

.model-list {
  width: 100vw;
  margin-bottom: 20px;
}

.model-item {
  display: flex;
  align-items: center;
  padding: 16px;
  margin-bottom: 12px;
  border-radius: 8px;
  position: relative;
  cursor: pointer;
}

.model-item:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -6px;
  height: 1px;
  background: #e5e5e5;
}

.model-item.active {
  /* border-color: #4080FF;
  background: #F5F8FF; */
}

.model-name {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 4px;
}

.model-info {
  flex: 1;
  min-width: 0;
}

.model-desc {
  font-size: 14px;
  color: #666;
  word-break: break-all;
}

.radio-btn {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid #e5e5e5;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 10px;
  flex-shrink: 0;
}

.model-item.active .radio-btn {
  border-color: #4080ff;
}

.radio-inner {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #4080ff;
}

.confirm-btn {
  position: fixed;
  bottom: 20px;
  left: 20px;
  right: 20px;
  height: 44px;
  background: #4080ff;
  color: white;
  border-radius: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
</style>
